<template>
  
  <div class="All">
        <!-- <p>{{user.userName}}</p>
        <p v-if="user.isMerchant">出租用户</p>
        <p v-else>普通用户</p>
        <p v-if="user.isCheck">身份已认证</p>
        <p v-else>身份未认证</p> -->
        <!-- 显示状态 -->
        <!-- <div v-if="user.isToCheck">身份正在认证 
          <button @click="getNew('isCheck')">更新认证结果</button>
          </div>
        <div v-if="user.isToMerchant">卖家身份正在审核中
              <button @click="getNew('isMerchant')">更新审核结果</button>
        </div> -->
        <!-- 显示待认证的 -->

          <el-table
    :data="data"
    style="width: 100%">
    <el-table-column
      label="用户名"
      width="180">
      <template slot-scope="scope">
        <i class="el-icon-user"></i>
        <span style="margin-left: 10px">{{ scope.row.userName }}</span>
      </template>
    </el-table-column>

    <el-table-column
      label="身份证号"
      width="250">
      <template slot-scope="scope">
        <i class="el-icon-paperclip"></i>
        <span style="margin-left: 10px">{{ scope.row.idCard }}</span>
      </template>
    </el-table-column>

    <el-table-column
      label="身份证姓名"
      width="180">
      <template slot-scope="scope">
        <i class="el-icon-user-solid"></i>
        <span style="margin-left: 10px">{{ scope.row.idName }}</span>
      </template>
    </el-table-column>
    
   <el-table-column
      label="驾驶证照片"
      width="150">
      <template slot-scope="scope">
        <img class="img" :src='scope.row.cardImg'>
      </template>
    </el-table-column>

    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini"
          @click="argree(scope.row._id,1)">同意认证</el-button>
        <el-button
          size="mini"
          type="danger"
          @click="argree(scope.row._id,2)">拒绝认证</el-button>
      </template>
    </el-table-column>
  </el-table>
    <el-pagination
  small
  layout="prev, pager, next"
  :page-size="limitpage*10"
  :current-page="pageNow"
  @current-change="toPage"
  @prev-click="prevPage"
  @next-click="nextPage"
  :total="total*10">
</el-pagination>
  </div>
</template>

<script>
import axios from 'axios';
export default {
      data(){
          return{
                data:[],
                limitpage:2,
                pageNow:1,
                total:0
                // Sdata:[],
                // user:{}
          }
      },
      mounted(){
          this.login()
          this.getdata()
      },
      methods:{
        // 分页
        // 去任意页
        toPage(e){
            console.log(e);
            this.pageNow=e
            console.log(this.pageNow);
            this.getdata()
        },
        //上一页
        prevPage(e){
            this.pageNow=this.pageNow-1;
            this.getdata()
        },
        // 下一页
        nextPage(e){
               this.pageNow=this.pageNow+1;
               this.getdata()
        },
        // 消息推送
          // getNew(which){
          //     axios.post('/users/login',{
          //        iphone:'18773303099',
          //        password:'123'
          //   }).then((res)=>{
          //         console.log(res);
          //         if(this.user[which]!==res.data.result[0][which]){
          //              alert('审核成功')
          //         }
          //         this.user=res.data.result[0];
                  
          //   })
          // },
        // 同意或者拒绝认证
          argree(  user_id,ifTrue){
            
            if(ifTrue==1){
                  axios.put('/users/ok',{
                   user_id,
                   isSuccess:true
               }).then((res)=>{
                  if(res.data.code==1){
                     this.getdata()
                  }
            })
            }else{
              axios.put('/users/ok',{
                     user_id,
                   isSuccess:false
               }).then((res)=>{
                 if(res.data.code==1){
                     this.getdata()
                  }
            })
            }
               
               
          },
          getdata(){
             // 获取需要认证的用户
            axios.post('/users/getRz',{
              limitpage:this.limitpage,
              pageNow:this.pageNow
              }).then((res)=>{
                  console.log(res);
                  this.data=res.data.result;
                  this.total=res.data.total
            })
          },
          login(){
            
            // 用户认证
            // axios.put('/users/check',{
            //      user_id:'5e9d748cfba0191764aa48ba',
            //      idCard:'360721199709111234',
            //      idName:'彭家'
            // }).then((res)=>{
            //       console.log(res);
                  
            // })
            // 登录
            // axios.post('/users/login',{
            //      iphone:'18773303099',
            //      password:'123'
            // }).then((res)=>{
            //       console.log(res);
                  
            // })
          },

      }
}
</script>

<style lang="less" scoped>
.All{
    background-color: rgb(255, 255, 255);
    padding: 50px;
    .img{
      width:100%;
      height:30%
    }
}
</style>